// @charset "utf-8";
/**
 * 融资融券获取shdata
 */
define(function (require, exports, module) {
	var hqQuote = {
		request: async function(callback, stocks, period, time) {
			var quote = ['open', 'close', 'ZQMC'];
			var thsQuote = null;
			try {
				thsQuote = new ThsQuote();
			} catch (e) {
				alert('需要客户端环境');
				return false;
			}
			var stocksStr = stocks.join(','),
				quoteStr = quote.join(',');
			//实时行情请求
			var reqObj = {
				code: stocksStr,
				type: quoteStr,
				period: period,
				time: time,
				onready: async function() {
					var data = [];
					var len = time.length;
					for (var n = 0; n < len; n++) {
						var param = {
							code: stocksStr,
							period: period,
							time: time[n]
						};
						var codeData = [];
						for (var i in quote) {
							param.type = quote[i];
							var tmpObj = await thsQuote.getData(param);
							try {
								tmpObj = eval('(' + tmpObj + ')');
							} catch (e) {
								return;
							}
							var valueData = [];
							for (var j in tmpObj) {
								for (var k in tmpObj[j]) {
									if (k == 'time') {
										continue;
									} else {
										var tmp = tmpObj[j][k];
										valueData.push("'" + j + "':'" + tmp + "'");
									}
								}
							}
							codeData.push("'" + quote[i] + "':{" + valueData.join(',') + "}");
						}
						data.push("'" + time[n] + "':{" + codeData.join(',') + "}");
					}
					callback(eval('({' + data.join(',') + '})'));
				}
			};
			await thsQuote.request(reqObj);
		}
	};
	module.exports = hqQuote;
});